package com.wr.async.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

@Service
public class TestService {

    @Async
    public Future<String> show() throws InterruptedException {
        System.out.println("异步开始");
        Thread.sleep(10000);
        System.out.println("休眠结束");
        return AsyncResult.forValue("休眠");
    }




    @Async
    public CompletableFuture<String> CompletableFuture()  {
        CompletableFuture<String> stringCompletableFuture = new CompletableFuture<>();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        stringCompletableFuture.obtrudeValue("带回结果");
        return stringCompletableFuture;
    }


    // 计数器调用方法
    public void print(){
        System.out.println("--------------达到次数-------------------");
    }
}
